part of 'table.dart';

class User implements Jsonable {
  /// 唯一且自增的用户id，由数据库生成
  final int id;

  /// 手机号，为另一个主键
  String phone;

  /// 当前是否有正在发送的验证码
  Sms? sms;

  String nick;
  bool isAdmin;

  User({
    required this.id,
    required this.phone,
    required this.nick,
    required this.sms,
    required this.isAdmin,
  });

  factory User.fromRaw(Json raw) => User(
        id: raw["id"],
        nick: raw["nick"],
        isAdmin: raw["is_admin"],
        phone: raw["phone"],
        sms: raw["sms"] == null ? null : Sms.fromRaw(raw["sms"]),
      );

  @override
  Json toJson() => {
        "id": id,
        "nick": nick,
        "is_admin": isAdmin,
        "phone": phone,
        "sms": sms?.toJson(),
      };
}
